#include "latch.h"
#include "mutex_lock.h"

namespace mars {

Latch::Latch(): 
    _mutex(), 
    _cond(),
     _status(false)    {
}

void Latch::open() {
    MutexLockGuard guard(_mutex);
    _status = true;
    _cond.notifyAll();
}

void Latch::close() {
    MutexLockGuard guard(_mutex);
    _status = false;
    _cond.notifyAll();
}

void Latch::wait() {
    MutexLockGuard guard(_mutex);
    while(!_status) {
        _cond.wait(_mutex);
    }
}




} // namespace mars
